package com.yanqu.road.server.cmd.activity.relation;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cookboyactivity.CookBoyActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.CrossRelationActivityMgr;
import com.yanqu.road.server.manager.chefduel.CrossChefDuelMgr;
import com.yanqu.road.server.manager.cookboy.CrossCookBoyMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CROSS_RELATION_ACTIVITY_GET_SPECIAL_REWARD, desc = "领取小当家类型活特殊奖励")
public class CrossGetSpecialRewardCmd extends CrossCommand {
    private int activityId;
    private int conditionId;
    private long userId;
    private String params;
    private boolean oneKey;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CookBoyActivityProto.CrossActivityGetSpecialRewardReqMsg reqMsg = CookBoyActivityProto.CrossActivityGetSpecialRewardReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionId = reqMsg.getConditionId();
        params = reqMsg.getParams();
        userId = packet.getPlayerId();
        if(reqMsg.hasOneKey()){
            oneKey = reqMsg.getOneKey();
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        String crossParams = "";
        ActivityConditionInfo activityConditionInfo = CrossRelationActivityMgr.getActivityConditionInfo(activityId, conditionId);
        if(null != activityConditionInfo){
            if(activityConditionInfo.getType() == eGamePlayerEventType.CookBoy3OpenBanquetTimes.getValue()) {
                crossParams = CrossCookBoyMgr.getCookBoy3BanquetTimes(activityId,params);
            }else if(activityConditionInfo.getType() == eGamePlayerEventType.CookBoy3AllBanquetUserCount.getValue()){
                crossParams = CrossCookBoyMgr.getCookBoy3BanquetUserCount(activityId,params);
            }else if(activityConditionInfo.getType() == eGamePlayerEventType.ChefDuel3AllBanquetUserCount.getValue()){
                crossParams = CrossChefDuelMgr.getChefDuel3BanquetTimes(activityId,params);
            }
        }
        CookBoyActivityProto.CrossActivityGetSpecialRewardRespMsg.Builder respMsg = CookBoyActivityProto.CrossActivityGetSpecialRewardRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setConditionId(conditionId);
        respMsg.setParams(params);
        respMsg.setOneKey(oneKey);
        respMsg.setCrossParams(crossParams);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_COOK_BOY_GET_SPECIAL_REWARD_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
